/*
 * @Author: 李慧贤 @lihuixian19990204
 * @Date: 2023-03-08 15:07:49
 * @LastEditors: baron
 * @LastEditTime: 2025-04-17 15:53:31
 * @FilePath: \ipec\src\utils\login.js
 * @Description: 登录
 */
import {
    login
} from '@/api/user';
import {
    baseURL
} from '@/utils/requestUtils';
export const hasLogin = async () => {
    return new Promise((resolve, reject) => {
        uni.setStorageSync('userInfo', '{}');
        uni.setStorageSync('storeInfo', '{}');
        const that = this;
        console.log(baseURL, '===baseURL=')
        wx.login({
            success(res) {
                login({
                        code: '',
                        uuid: '',
                        username: 'admin',
                        password: 'admin123@',
                    })
                    .then(res => {
                        console.log('login信息==', res);
                        if (res) {
                            uni.setStorageSync('token', res.token);
                            resolve(res);
                        } else {
                            console.log('reject(res)')
                            reject(res)
                        }
                    })
                    .catch(msg => {
                        console.log(msg, '---msg---')
                        reject(msg);
                        console.log(msg);
                    });


                // console.log(res.code, '    res.code-')
                return

                wx.getSystemInfo({
                    success(system) {
                        login({
                                code: res.code,
                                mac: '',
                                os: system.model,
                                osInfo: system.system,
                            })
                            .then(res => {
                                if (res.data) {
                                    const {
                                        data
                                    } = res;
                                    const userInfo = {
                                        ...res.data
                                    }
                                    console.log('用户信息==', userInfo);
                                    uni.setStorageSync('userInfo', JSON.stringify(userInfo));
                                    uni.setStorageSync('token', res.data.token);
                                    resolve(userInfo);
                                } else {
                                    console.log('reject(res)')
                                    reject(res)
                                }
                            })
                            .catch(msg => {
                                console.log(msg, '---msg---')
                                reject(msg);
                                console.log(msg);
                            });
                    }
                });
            },
            fail(error) {

                console.log(error, '--error---login-')
            }
        });
    });
};